﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Framework.Packets
{
    /// <summary>
    /// Packet interpreter.
    /// Inherites IPacketHandler.
    /// </summary>
    public class PacketReader : IPacketHandler
    {
        /// <summary>
        /// IPacket we're reading.
        /// </summary>
        private IPacket packet;

        /// <summary>
        /// Current buffer length. Can be casted to ushort.
        /// </summary>
        public long Length { get { return packet.Data.Length; } }

        /// <summary>
        /// Packet reader.
        /// Creates uniform wrapper around byte array.
        /// </summary>
        /// <param name="data"></param>
        public PacketReader(byte[] data)
        {
            this.packet = (IPacket) new Packet() { Data = data}; // TODO: reform to another view. To avoid such casting.
        }

        /// <summary>
        /// Packet reader.
        /// Creates uniform wrapper around IPacket instance.
        /// </summary>
        /// <param name="packet"></param>
        public PacketReader(IPacket packet)
        {
            this.packet = packet;
        }

        /// <summary>
        /// Returns byte
        /// </summary>
        /// <returns></returns>
        public byte[] Data
        {
            get { return packet.Data; }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public IPacket Packet
        {
            get { return packet; }
        }


        public int Position
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }
    }
}
